package com.iwunu.gateway.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.iwunu.gateway.entity.GatewayDevice;

import io.lettuce.core.dynamic.annotation.Param;

/**
 * @author kinfeng
 * @date 2021/3/9 10:00 AM
 * @desc
 */
@Repository
public interface GatewayRepository extends JpaRepository<GatewayDevice, Long> , JpaSpecificationExecutor<GatewayDevice> {

    @Query(value="select i from GatewayDevice i where i.uuid=:uuid and i.isDel= false")
    GatewayDevice selectGatewayByUUID(@Param("uuid") String uuid);
    
    @Query(value="select i from GatewayDevice i where i.mac=:mac and i.isDel= false ")
    GatewayDevice selectGatewayByMac(@Param("mac") String mac);
    
    @Query(value="update GatewayDevice i set i.isDel=true where  i.mac=?1 ")
     int updateByMac(@Param("mac") String mac);
}
